<template>
  <div class="inputTi">
    <el-popover placement="top-start" trigger="focus">
      <div class="popoverCon" v-if="!disabled">
        <el-upload
          :action="define.comUploadUrl + '/' + modular + '/' + type"
          :show-file-list="false"
          :on-success="handleSuccess"
          :headers="uploadHeaders"
          :multiple="isTitle"
          :limit="limit"
          :on-remove="handleRemove"
          accept="image/*"
        >
          <i style="cursor: pointer" class="el-icon-picture-outline"></i>
        </el-upload>
      </div>

      <el-input
        slot="reference"
        class="input"
        v-model="input"
        :placeholder="placeholder"
        @input="inputValChange"
        :disabled="disabled"
        v-trim
      ></el-input>
    </el-popover>
    <div class="imgBox" v-if="fileList && fileList.length > 0">
      <template v-for="(imageUrl, i) in fileList">
        <el-image
          v-if="imageUrl"
          class="img"
          :key="i"
          :src="define.comUrl + imageUrl"
          :preview-src-list="getImgList(fileList)"
        >
        </el-image>
      </template>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    isTitle: {
      type: Boolean,
      default: false,
    },
    idx: {
      type: Number,
      default: 0,
    },
    inputVal: {
      type: String,
      default: "",
    },
    placeholder: {
      type: String,
      default: "",
    },
    fileList: {
      type: Array,
      default: () => [],
    },
    modular: {
      type: String,
      default: "system",
    },
    type: {
      type: String,
      default: "annex",
    },
    isremove: {
      type: Boolean,
      default: true,
    },
    disabled: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      limit: this.isTitle ? 3 : 1,
      uploadHeaders: { Authorization: this.$store.getters.token },
      input: this.inputVal,
      // dialogImageUrl: [],
    };
  },
  computed: {},
  watch: {
    inputVal() {
      this.input = this.inputVal;
    },
    fileList() {},
  },
  created() {
    console.log("limit", this.limit);
  },
  mounted() {},
  methods: {
    inputValChange(v) {
      if (this.isTitle) {
        this.$emit("input", v);
      } else {
        this.$emit("input", this.idx, v);
      }
    },
    getImgList(list) {
      const newList = list.map((o) => this.define.comUrl + o);
      return newList;
    },
    handleSuccess(res, file) {
      if (res.code == 200) {
        if (this.isTitle) {
          this.fileList.push(res.data.url);
          this.$emit("changeImg", this.fileList);
        } else {
          this.fileList[0] = res.data.url;
          this.$emit("changeImg", this.idx, res.data.url);
        }
      } else {
        this.$message({ message: res.msg, type: "error", duration: 1500 });
      }
    },
    // 上传图片方法
    handleChange(file, fileList) {
      console.log("response", file, fileList);
      // this.dialogImageUrl = [...fileList]
      // this.$emit("changeImg", {
      //   id: this.inputData.id,
      //   imgList: [...fileList],
      // });
      // console.log("this.inputData", this.inputData);
    },
    handleRemove(file, fileList) {
      // this.dialogImageUrl = [...fileList]
    },
  },
};
</script>
<style lang="scss">
.el-popover {
  min-width: 30px !important;
  font-size: 20px;
}
.inputTi {
  align-items: center;
  .el-input__inner {
    border-color: rgba(255, 255, 255, 0);
    
    &[disabled] {
      background-color: #F5F7FA;
      border-color: #E4E7ED;
      color: #909399;
      cursor: not-allowed;
    }
  }
}

.popoverCon {
  // .el-upload--picture-card {
  //     width: 40px !important;
  //     min-width: 40px !important;
  //     height: 40px !important;
  //     line-height: 50px !important;
  //     font-size: 35px;

  // }

  .el-upload {
    font-size: 30px;
    width: 30px !important;
    min-width: 30px !important;
    height: 30px !important;
    line-height: 40x !important;
  }
}
</style>
<style lang="scss" scoped>
.inputTi {
  width: 400px;
}

.imgBox {
  width: 437px;
  // margin-left: 10px;
  margin-top: 10px;

  .img {
    width: 100%;
    margin-top: 10px;
  }
}
</style>
